const express = require('express');
const router = express.Router();
const multer = require('multer');
// 创建 Multer 中间件，用于处理文件上传
const storage = multer.diskStorage({
	destination: (req, file, cb) => {
		cb(null, 'document/uploads');
	},
	filename: (req, file, cb) => {
		const extension = file.originalname.split('.').pop();
		cb(null, `${Date.now()}.${extension}`);
	}
});
const upload = multer({storage: storage});

// 上传
router.post('/upload', upload.single('file'), (req, res) => {
	const host = req.headers.host;
	const imageUrl = `http://${host}/uploads/${req.file.filename}`;
	res.json({imageUrl});
});


//

module.exports = router;